package com.naiterui.ehp.bs.doctor.controller.inner;

import com.naiterui.ehp.bp.constants.SwaggerTag;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bp.support.exception.PublicService;
import com.naiterui.ehp.bp.support.exception.ResponseVO;
import com.naiterui.ehp.bp.support.mvc.RequestHeaderDecode;
import com.naiterui.ehp.bs.doctor.exception.ExceptionCodes;
import com.naiterui.ehp.bs.doctor.service.record.IRecordInfoService;
import com.naiterui.ehp.bs.doctor.vo.record.RecordHospitalVO;
import com.naiterui.ehp.bs.doctor.vo.record.RecordInfoVO;

import lombok.extern.slf4j.Slf4j;

/**
 * @author guoyongxiang
 * @date 2020/2/17 16:32
 * @since 1.0.0
 */
@Slf4j
@RequestMapping("ad/inner/cms/record")
@RestController
@Api(tags = {SwaggerTag.DOCTOR + SwaggerTag.INNER_API + SwaggerTag.AUTH_RECORD})
public class AdInnerCmsRecordController {

    @Autowired
    @Qualifier("recordInfoDoctorServiceImpl")
    private IRecordInfoService recordInfoDrService;
    @Autowired
    @Qualifier("recordInfoPharmacistServiceImpl")
    private IRecordInfoService recordInfoPhService;
    @Autowired
    private RecordHospitalVO recordHospitalVO;

    /**
     * 更新医生备案信息
     *
     * @param recordInfoVO
     * @param operator
     *
     * @return
     *
     * @throws BusinessException
     */
    @PostMapping("doctor/update")
    public ResponseVO<Void> doctorUpdate(@RequestBody RecordInfoVO recordInfoVO, @RequestHeaderDecode String operator) throws BusinessException {
        log.info("更新医生备案信息 data:{}, operator:{}", JSON.toJSON(recordInfoVO), operator);
        this.recordInfoDrService.updateUserInfo(recordInfoVO, operator);
        return PublicService.returnResponseVO(ExceptionCodes.SUCCESS);
    }

    @PostMapping("pharmacist/update")
    public ResponseVO<Void> pharmacistUpdate(@RequestBody RecordInfoVO recordInfoVO, @RequestHeaderDecode String operator) throws BusinessException {
        log.info("更新药师信息 data:{}, operator:{}", JSON.toJSON(recordInfoVO), operator);
        this.recordInfoPhService.updateUserInfo(recordInfoVO, operator);
        return PublicService.returnResponseVO(ExceptionCodes.SUCCESS);
    }

    @GetMapping("hospital/info")
    public ResponseVO<RecordHospitalVO> hospitalInfo() {
        return PublicService.returnResponseVO(ExceptionCodes.SUCCESS, recordHospitalVO);
    }
}
